package com.example.sports_meet.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.sports_meet.R;
import com.example.sports_meet.entity.Essay;

import java.util.List;

public abstract class EssayAdapter extends RecyclerView.Adapter<EssayAdapter.ViewHolder> {

    private List essays;

    public EssayAdapter(List essays) {
        this.essays = essays;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_essay, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Essay essay = (Essay) essays.get(position);
        holder.titleTextView.setText(essay.getTitle());
        holder.contentTextView.setText(essay.getContent());
    }

    @Override
    public int getItemCount() {
        return essays.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView titleTextView;
        public TextView contentTextView;

        public ViewHolder(View itemView) {
            super(itemView);

            titleTextView = itemView.findViewById(R.id.titleTextView);
            contentTextView = itemView.findViewById(R.id.contentTextView);
        }
    }
}